package com.rockcent;

import com.rockcent.common.BaseConfig;
import com.rockcent.job.Config;
import com.rockcent.job.Prop;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * Created by zhangjh on 2016/11/22.
 */
@SpringBootApplication
@EnableScheduling
@EnableAutoConfiguration
public class BootstrapJob {


    public static void main(String[] args) throws Exception {
        SpringApplication app = new SpringApplication(BootstrapJob.class);
        app.setBannerMode(Banner.Mode.LOG);
        ApplicationContext applicationContext = app.run(args);

        Prop prop = (Prop) applicationContext.getBean("prop");

        // 是否生产
        if (applicationContext.getEnvironment().getActiveProfiles() != null && applicationContext.getEnvironment().getActiveProfiles().length > 0) {
            if (applicationContext.getEnvironment().getActiveProfiles()[0].contains(Config.PROD)) {
                prop.env = BaseConfig.PROD;
            } else if (applicationContext.getEnvironment().getActiveProfiles()[0].contains(Config.UAT)) {
                prop.env = BaseConfig.UAT;
            } else if (applicationContext.getEnvironment().getActiveProfiles()[0].contains(Config.DEV)) {
                prop.env = BaseConfig.DEV;
            } else {
                prop.env = BaseConfig.LOCAL;
            }
        }
    }
}
